package org.windey.server;

import org.windey.Debug;

/**
 * 
 * 
 *
 */
public class WindeyStreamThread extends Thread
{	
	/**
	 * 
	 */
	private WindeyConnection connection1;
	/**
	 * 
	 */
	private WindeyConnection connection2;
	
	/**
	 * 
	 * @param conn1
	 * @param conn2
	 */
	public WindeyStreamThread(WindeyConnection conn1, WindeyConnection conn2)
	{
		this.setConnection1(conn1);
		this.setConnection2(conn2);
	}
	
	/**
	 * 
	 */
	public void run()
	{
		String dataLine;
		try
		{
			while (!(dataLine = getConnection1().receive()).equalsIgnoreCase("EOC")
					&& this.getConnection1().getSocket().isConnected() && this.getConnection2().getSocket().isConnected())
			{
				getConnection2().send(dataLine);
			}
		}
		catch (NullPointerException e)
		{
			
		}
		getConnection2().send("EOC");
		getConnection1().setLinked(false);
		getConnection1().setOffline();
		getConnection1().setRunning(false);
		getConnection1().setLinked(false);
		getConnection2().setRunning(false);
		Debug.debug("windeystreamthread terminated");
	}

	public void setConnection1(WindeyConnection conn1) {
		this.connection1 = conn1;
	}

	public WindeyConnection getConnection1() {
		return connection1;
	}

	public void setConnection2(WindeyConnection connection2) {
		this.connection2 = connection2;
	}

	public WindeyConnection getConnection2() {
		return connection2;
	}
}
